<%@ page contentType="text/html; charset=UTF-8" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql" %>

<c:if test="${userID==null}">
  <c:redirect url="index.jsp" />
</c:if>

<c:if test="${userType!='A'}">
  <c:redirect url="main.jsp" />
</c:if>

<c:if test="${pageContext.request.method=='POST'}">
  <c:if test="${param.cancel!=null}">
    <c:redirect url="users.jsp" />
  </c:if>

  <sql:update dataSource="${dataSource}">
  update t_users set c_type = ? where c_uid = ? 
  <sql:param value="${param.type}" />

  <sql:param value="${param.uid}" />
  </sql:update>
  <c:redirect url="users.jsp" />
</c:if>

<html>
  <head>
    <title><fmt:message key="edituser.title" bundle="${lang}"/></title>
  </head>

  <body>
    <sql:query var="users" dataSource="${dataSource}">
    select c_uid,c_pwd,c_accesses,c_first,c_last,c_bad,c_posted,c_type from t_users where c_uid = ? 
    <sql:param value="${param.target}" />
    </sql:query>

<p><fmt:message key="edituser.ins" bundle="${lang}"/>
  
    <c:forEach var="row" items="${users.rows}">
      <table border="0">
        <form method="post">
          <tr>
            <td colspan="2" bgcolor="#0000FF">
              <p align="center">
                <b>
                  <font size="4" color="#FFFFFF">
                  <fmt:message key="edituser.title" bundle="${lang}"/></font>
                </b>
              </p>
            </td>
          </tr>

          <tr bgcolor="#FFFF66">
            <td bordercolor="#000000"><fmt:message key="welcome.id" bundle="${lang}"/></td>

            <td>
              <c:out value="${row.c_uid}" />

              <input type="hidden" name="uid" value="<c:out value="${row.c_uid}"/>" />
            </td>
          </tr>

          <tr>
            <td><fmt:message key="welcome.type" bundle="${lang}"/></td>

            <td>
              <select name="type">
                <option value="A"
                  <c:if test="${row.c_type=='A'}">SELECTED</c:if>
                ><fmt:message key="type.a" bundle="${lang}"/></option>
                <option value="R"
                <c:if test="${row.c_type=='R'}">SELECTED</c:if>
                ><fmt:message key="type.r" bundle="${lang}"/></option>
                <option value="G"
                <c:if test="${row.c_type=='G'}">SELECTED</c:if>
                ><fmt:message key="type.g" bundle="${lang}"/></option>
              </select>
            </td>
          </tr>

          <tr bgcolor="#FFFF66">
            <td><fmt:message key="welcome.times" bundle="${lang}"/></td>

            <td>
              <c:out value="${row.c_accesses}" />
            </td>
          </tr>

          <tr>
            <td><fmt:message key="welcome.first" bundle="${lang}"/></td>

            <td>
              <fmt:formatDate value="${row.c_first}" />
            </td>
          </tr>

          <tr bgcolor="#FFFF66">
            <td><fmt:message key="welcome.last" bundle="${lang}"/></td>

            <td>
              <fmt:formatDate value="${row.c_last}" />
            </td>
          </tr>

          <tr>
            <td><fmt:message key="welcome.failed" bundle="${lang}"/></td>

            <td>
              <c:out value="${row.c_bad}" />
            </td>
          </tr>

          <tr bgcolor="#FFFF66">
            <td><fmt:message key="welcome.posted" bundle="${lang}"/></td>

            <td>
              <c:out value="${row.c_posted}" />
            </td>
          </tr>

          <tr>
            <td colspan="2">
              <center>
                <input type="submit" name="save" value="<fmt:message key="button.save" bundle="${lang}"/>" />

                <input type="submit" name="cancel"
                value="<fmt:message key="button.cancel" bundle="${lang}"/>" />
              </center>
            </td>
          </tr>
        </form>
      </table>
    </c:forEach>
  </body>
</html>

